<?php

namespace app\admin\controller\resource;

use app\common\controller\Backend;
use app\common\model\ResourceItem as ResourceItemModel;

/**
 * 谋士管理
 *
 * @icon fa fa-user-secret
 */
class Item extends Backend
{
    protected $model = null;
    protected $searchFields = ['title'];
    protected $relationSearch = true;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new ResourceItemModel;
        $this->assign('typeList', model('UserResource')->where('status', 'normal')->column('name', 'id'));
    }
    /**
     * 查看
     */
    public function index()
    {
        if ($this->request->isAjax()) {
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
            $list = $this->model
                ->with(['resource'])
                ->where($where)
                ->order($sort, $order)
                ->paginate($limit);
            $result = array(
                "total" => $list->total(),
                "rows" => $list->items()
            );
            return json($result);
        }
        return $this->view->fetch();
    }
    
}